﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASPPatterns.Chap3.Layered.Model
{
    public class Price
    {
        private IDiscountStrategy _discountStrategy = new NullDiscountStrategy();
        private decimal _rrp;

        public decimal RRP
        {
            get { return _rrp; }
            set { _rrp = value; }
        }

        private decimal _sellingPrice;

        public decimal SellingPrice
        {
            get { return _sellingPrice; }
            set { _sellingPrice = value; }
        }

        public void SetDiscountStrategyTo(IDiscountStrategy discountStrategy)
        {
            this._discountStrategy = discountStrategy;
        }

        public Price(decimal rrp, decimal sellingPrice)
        {
            this._rrp = rrp;
            this._sellingPrice = sellingPrice;
        }

        public decimal Discount
        {
            get
            {
                if (this._rrp > this._sellingPrice)
                {
                    return this._rrp - this._sellingPrice;
                }
                else
                {
                    return 0;
                }
            }
        }

        public decimal Savings
        {
            get
            {
                if (this._rrp > this._sellingPrice)
                {
                    return 1 - (this._sellingPrice / this._rrp);
                }
                else
                {
                    return 0;
                }
            }
        }

        
    }
}
